package com.labuladong;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称: java_algorithm
 * @ClassName FullPermutation
 * @Description 全排列数据不存在重复的
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2022/6/17 10:22
 */
public class FullPermutation {

    static List<List<Integer>> res = new ArrayList<>();

    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3};
        List<Integer> track = new ArrayList<>();
        backTrack(track, nums);
        System.out.println(res);
    }

    public static void backTrack(List<Integer> track, int[] nums) {
        if (track.size() == nums.length) {
            res.add(new ArrayList<>(track));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (track.contains(nums[i])) {
                continue;
            }
            track.add(nums[i]);
            backTrack(track, nums);
            track.remove(track.size() - 1);
        }
    }
}
